/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package service.costCalculator;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import tools.costTools.BeerCostTools;

/**
 *
 * @author chapmand
 */
@Stateless
@Path("com.openbrew.openbrewrf.costcalculator")
public class CostCalculatorREST {
    @PersistenceContext(unitName = "com.openBrew_openBrewRF_war_1.0PU")
    private EntityManager em;
    
    public CostCalculatorREST() {
    }
    
    @GET
    @Path("beerCost/{id}")
    @Produces(MediaType.TEXT_PLAIN)
    public String findBeerCost(@PathParam("id") int id){
        BeerCostTools bct = new BeerCostTools();
        double cost = bct.getBeerCost(em, id);
        return Double.toString(cost);
    }
    
    @GET
    @Path("labCost/{id}/{bbl}/{days}")
    @Produces(MediaType.TEXT_PLAIN)
    public String findLabCost(@PathParam("id") int id, @PathParam("bbl") double bbl
            , @PathParam("days") int days){
        BeerCostTools bct = new BeerCostTools();
        double cost = bct.getLabCost(em, id, bbl, days);
        return Double.toString(cost);
    }
    
    @GET
    @Path("procedureCost/{id}/{bbl}/{days}")
    @Produces(MediaType.TEXT_PLAIN)
    public String findProcedureCost(@PathParam("id") int id, @PathParam("bbl") double bbl
            , @PathParam("days") int days){
        BeerCostTools bct = new BeerCostTools();
        double cost = bct.getProcedureCost(em, id, bbl, days);
        return Double.toString(cost);
    }
    
    @GET
    @Path("processStepCost/{id}/{bbl}/{days}")
    @Produces(MediaType.TEXT_PLAIN)
    public String findProcessStepCost(@PathParam("id") int id, @PathParam("bbl") double bbl
            , @PathParam("days") int days){
        BeerCostTools bct = new BeerCostTools();
        double cost = bct.getProcessStepsCost(em, id, bbl, days);
        return Double.toString(cost);
    }
    
    @GET
    @Path("packageTypeCost/{id}/{bbl}")
    @Produces(MediaType.TEXT_PLAIN)
    public String findPackageTypeCost(@PathParam("id") int id, @PathParam("bbl") double bbl){
        BeerCostTools bct = new BeerCostTools();
        double cost = bct.getPackageTypeCost(em, id, bbl);
        return Double.toString(cost);
    }
    
    @GET
    @Path("calculateRecipe/{id}")
    @Produces(MediaType.TEXT_PLAIN)
    public String findPackageTypeCost(@PathParam("id") int id){
        BeerCostTools bct = new BeerCostTools();
        double cost = bct.getRecipeCost(em, id);
        return Double.toString(cost);
    }
    
    @GET
    @Path("calculateFGI/{id}/{bbl}")
    @Produces(MediaType.APPLICATION_XML)
    public CostCalcResults calculateFGI(@PathParam("id") int id, @PathParam("bbl") double bbl){
        BeerCostTools bct = new BeerCostTools();
        CostCalcResults ccr = bct.runFGICalc(em, id, bbl);
        return ccr;
    }
    
    protected EntityManager getEntityManager() {
        return em;
    }
}
